package com.zit.java.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
@Aspect
public class MyAspect {
//    execution(* com.xyz.service.. * . * (..)) 子包
    @Before("execution(* com.zit.java.service..*.*(..))")
    public void before(){
        System.out.println("=========前置通知启动==========");

    }

    @After("execution(* com.zit.java.service..*.*(..))")
    public void after(){
        System.out.println("=======后置通知=======");
    }


    @Around("execution(* com.zit.java.controller..*.*(..))")
    public Object around(ProceedingJoinPoint p) throws Throwable {
         Object obj =   p.proceed();
         Class<?> clazz =    obj.getClass();
       Method[] methods =  clazz.getMethods();

       for (Method method : methods){
           System.out.println(method.getName());
       }
        return obj;
    }
}
